package common.main.common;

import common.main.cnkiJournalPaper.CnkiJournalPaperConfig;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class BaseSaveDataToSql {

    protected static Connection conn = null;
    protected static Statement stmt = null;


    public static void connectDatabase() throws ClassNotFoundException, IllegalAccessException, InstantiationException, SQLException {

        Class.forName("com.mysql.jdbc.Driver").newInstance();
        String url ="jdbc:mysql://"+CnkiJournalPaperConfig.mysqlHost +"/"
                +CnkiJournalPaperConfig.mysqlDatabaseName+"?user="+CnkiJournalPaperConfig.mysqlUserName+"&password="+CnkiJournalPaperConfig.mysqlPassword+"&useUnicode=true&characterEncoding=UTF-8";
        if(conn == null || conn.isClosed()){
            conn = DriverManager.getConnection(url);
        }
        if(stmt == null || stmt.isClosed()){
            stmt = conn.createStatement();
        }
    }
}
